package com.example.petcare.mapper;

import com.example.petcare.pojo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AdminMapper {

    // 根据用户名查询用户
    @Select("select * from provider where username = #{username}")
    Admin findByUsername(String username);

    // 查询服务商审核列表(没被拒绝的且没被审核的)
    @Select("select * from provider where provider_status = 0 and reject_status = 0")
    List<Provider> list();

    // 审核不通过（更新rejectStatus）
    @Select("update provider set reject_status = 1 and provider_status = 0 where provider_id = #{providerId}")
    void reject(Integer providerId);

    // 审核通过（更新providerStatus）
    @Select("update provider set provider_status = 1 where provider_id = #{providerId}")
    void pass(Integer providerId);

    // 根据id查询服务商
    @Select("select * from provider where provider_id = #{providerId}")
    Provider findById(Integer providerId);

    // 查看用户列表（分页查询）
    @Select("select * from user WHERE audit_status = 0")
    List<User> userList();

    // 审核通过（更新用户状态）
    @Select("update user set audit_status = 1 where user_id = #{userId}")
    void userPass(Integer userId);

    // 审核不通过（更新用户状态）
    @Select("update user set audit_status = 2 where user_id = #{userId}")
    void userReject(Integer userId);

    // 商品审核通过
    @Select("update goods set audit_status = 1 where g_id = #{gId}")
    void goodsPass(Integer gId);

    // 商品审核不通过
    @Select("update goods set audit_status = 2 where g_id = #{gId}")
    void goodsReject(Integer gId);

    // 添加审核意见,并且更新商品状态
    @Select("update goods set audit_comment = #{auditComment}, audit_status = 2 where g_id = #{gId}")
    void addAuditComment(Integer gId, String auditComment);


    // 获取所有待审核的商品列表(条件分页查询)
    List<Goods> getGoodsList(Boolean isOnSale, Double price, Integer providerId);

    // 查看用户宠物列表
    @Select("select * from pet where user_id = #{userId}")
    List<Pet> petlist(Integer userId);
}
